-- 层，全屏节点，没有宽高概念，点击判定范围是全屏
Layer = {
    dependencies = {
        Stretch
    }
}
function Layer:ctor()
    -- self:addComponent(Stretch)
end
function Layer:hitTest()
    return true
end

function Node.Layer()
    return Node.new():addComponent(Layer)
end


Layer.Stage = Node.Layer():addTo(Node.Root)
Layer.Stage.name = "stageLayer"
Layer.UI = Node.Layer():addTo(Node.Root)
local function optimizeCoverAllRendering()
    RenderSystem.renderSkip = {}
    local topScreen
    for i, screen in ipairs(Layer.UI.children) do
        if screen.coverAll then
            topScreen = screen
        end
    end
    if topScreen then
        RenderSystem.renderSkip[Layer.Stage] = true
        for i, Screen in ipairs(Layer.UI.children) do
            if Screen == topScreen then
                break
            end
            RenderSystem.renderSkip[Screen] = true
        end
    end
end
local function onAddScreen(screen)
    Console.log("onAddScreen")
    screen:on(ScreenEvent.CoverAll, optimizeCoverAllRendering)
    optimizeCoverAllRendering()
end
local function onRemoveScreen(screen)
    screen:off(ScreenEvent.CoverAll, optimizeCoverAllRendering)
end
Layer.UI:on(NodeEvent.AddChild, onAddScreen)
Layer.UI:on(NodeEvent.RemoveChild, onRemoveScreen)
Layer.UI.name = "uiLayer"

Layer.Top = Node.Layer():addTo(Node.Root)
Layer.Top.name = "topLayer"